package cn.tedu.mapper;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * LongWritable:k1行的偏移量
 * Text:v1一行的值
 * Text:k2,单词
 * LongWritable:v2 单词的出现的记为1
 */
public class MyMapper extends Mapper<LongWritable, Text,Text,LongWritable> {
    /**
     * 数据每一行都会调用一次map方法
     * @param key k1:进来的偏移量
     * @param value v1:一行的值
     * @param context 上下文
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] words = line.split(",");
        for (String word : words) {
            //通过context进行数据输出
            context.write(new Text(word), new LongWritable(1));
        }
    }
}
